package com.infitecs.eyas.mill.service;

import com.infitecs.eyas.constant.Constant;
import com.infitecs.eyas.mill.dao.MillSelectCalculateDao;
import com.infitecs.eyas.mill.dao.MillSelectDao;
import com.infitecs.eyas.mill.model.MillSelect;
import com.infitecs.eyas.mill.model.MillSelectCalculate;
import com.infitecs.eyas.power.dao.OperateFieldDao;
import com.infitecs.eyas.power.model.OperateField;
import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.session.model.Param;
import com.infitecs.eyas.step.modal.StepInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2015/6/28 0028.
 */
@Service
public class MillSelectCalculateService {
    @Autowired
    private MillSelectCalculateDao millSelectCalculateDao;
    @Autowired
    private MillSelectService millSelectService;
    @Autowired
    private MillSelectDao millSelectDao;
    @Autowired
    private SessionService sessionService;
    @Autowired
    private OperateFieldDao operateFieldDao;

    public MillSelectCalculate getSelectCalculate() {
        return millSelectCalculateDao.getSelectCalculate(sessionService.getCaseId());
    }

    public void addSelectCalculate() {
        int caseId = sessionService.getCaseId();
        millSelectCalculateDao.addSelectCalculate(caseId);
        sessionService.addStepState(new StepInfo(caseId, Constant.STEP_ID_12, Constant.STEP_OVER_STATE_0));
    }

    public void saveValueOfSelectCalculate(Param param) {
        param.setCaseId(sessionService.getCaseId());
        millSelectCalculateDao.saveValueOfSelectCalculate(param);
        param.setParamName(sessionService.getE() + param.getParamName());
        sessionService.putParamMap(param);
    }

    public void updateMill(MillSelectCalculate millSelectCalculate) {
        millSelectCalculate.setCaseId(sessionService.getCaseId());
        millSelectCalculateDao.updateMill(millSelectCalculate);
    }

    public void calculateSave(MillSelect millSelect) {
        MillSelect oldSelect = millSelectDao.getMillSelect(millSelect.getCaseId());
        oldSelect.setModelState(millSelect.getModelState());
        oldSelect.setModel(millSelect.getModel());
        OperateField operateField = operateFieldDao.getOperateField(millSelect.getCaseId());
        oldSelect.setMyglState(operateField.getMyglState());
        oldSelect.setE12State(operateField.getE12State());
        oldSelect.setE74State(operateField.getE74State());
        oldSelect.setE75State(operateField.getE75State());
        millSelectService.chooseDataSave(oldSelect);
    }
}
